package com.wl.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wl.entity.Buyerapprove_04;
import com.wl.entity.Check_05;
import com.wl.entity.Warehouse_06;
import com.wl.service.BuyerApprove_04Service;
import com.wl.service.Check_05Service;
import com.wl.service.Warehouse_06Service;
import com.wl.util.PageData;

@RestController
public class Check_05Controller {
	@Autowired
	private Check_05Service cs;
	@Autowired
	private BuyerApprove_04Service bas;
	@Autowired
	private Warehouse_06Service whs;

	@GetMapping(value = "/Check_05")
	public PageData<Check_05> listCheck_05ByPage(@RequestParam(defaultValue = "") String keywords,
			@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {
		PageData<Check_05> pd = cs.listCheck_05sByPage(keywords, page, limit);
		return pd;
	}

	@PostMapping(value = "/Check_05")
	public String insertCheck_05(@RequestBody Check_05 check_05) {
		int n = cs.insertSelective(check_05);
		if (n > 0) {
			return "success";
		} else {
			return "failure";
		}
	}

	/**
	 * 查询待办流程分页
	 * 
	 * @param keywords
	 * @param page
	 * @param limit
	 * @return
	 */
	@GetMapping(value = "/Check_05_wait")
	public PageData<Check_05> listCheck_05_waitByPage(@RequestParam(defaultValue = "") String checkno,
			@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {
		PageData<Check_05> pd = cs.listCheck_05_waitByPage(checkno, page, limit);
		return pd;
	}

	/**
	 * 查询已处理流程分页
	 * 
	 * @param keywords
	 * @param page
	 * @param limit
	 * @return
	 */
	@GetMapping(value = "/Check_05_approved")
	public PageData<Check_05> listCheck_05_approvedByPage(@RequestParam(defaultValue = "") String checkno,
			@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {
		PageData<Check_05> pd = cs.listCheck_05_approvedByPage(checkno, page, limit);
		return pd;
	}

	@PostMapping(value = "/Check_05_submit")
	public boolean updateByPrimaryKeySelective(@RequestBody Check_05 check_05, Warehouse_06 warehouse_06) {
		check_05.setCheckstatus(1);
		check_05.setCheckdetail("同意");
		warehouse_06.setFlowid(check_05.getFlowid());
		warehouse_06.setAppno("A123");
		warehouse_06.setAppstatus(1);
		int n = cs.updateByPrimaryKeySelective(check_05);
		return true;
	}

	@PostMapping(value = "/Check_05_return")
	public boolean updateByPrimaryKeySelective2(@RequestBody Check_05 check_05, Buyerapprove_04 buyerapprove_04) {
		check_05.setCheckstatus(2);
		check_05.setCheckdetail("不同意");
		int n = cs.updateByPrimaryKeySelective(check_05);
		buyerapprove_04.setFlowid(check_05.getFlowid());
		buyerapprove_04.setBuyerstatus(0);
		bas.insertSelective(buyerapprove_04);
		return false;
	}
}
